import uvicorn
from fastapi import FastAPI
from lxg import ssqUtil as ssq
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()
origins = [
    "http://localhost.tiangolo.com",
    "https://localhost.tiangolo.com",
    "http://localhost",
    "http://localhost:8080",
    "http://localhost:8081",
]
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)


@app.get("/ssq/api/v1/history/all")
async def history_all():
    """
    查询所有的双色球历史数据
    :return: 历史数据列表
    """
    return ssq.all()


@app.get("/ssq/api/v1/history/page")
async def history_page(page: int = 1, size: int = 20):
    """
    分页查询双色球历史中奖数据
    :return: 历史中奖数据分页列表
    """
    return ssq.page(page, size)


@app.get("/ssq/api/v1/next")
async def history_page(page: int = 1, size: int = 20):
    """
    下期预测的号码
    """
    return {
        'red': ssq.get_next_red_set(),
        'blue': ssq.get_next_blue_set()
    }


@app.get("/ssq/api/v1/public/num/all")
async def public_num_all():
    """
    数据库中所有的期号
    """
    return ssq.get_public_num_all()


@app.get("/ssq/api/v1/ball")
async def public_num_all(id: int = 1):
    """
    数据库中所有的期号
    """
    return ssq.get_ball_data(id)

@app.get("/ssq/api/v1/next/random")
async def public_num_all(num: int = 20):
    """
    数据库中所有的期号
    """
    return ssq.get_next_all_predication(num)


if __name__ == '__main__':
    uvicorn.run(app='main:app', host="0.0.0.0", port=8000, reload=True, debug=True)
